import { createRouter, createWebHistory } from 'vue-router'

import AboutPage from '../views/AboutPage.vue'
import AppHome from "@/views/AppHome.vue";
import AnnouncementList from '../views/AnnouncementList.vue'
import DownloadResources from '../views/DownloadResources.vue'

const routes = [
    {
        path: '/home',
        name: 'Home',
        component: AppHome
    },
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/about-page',
        name: 'AboutPage',
        component: AboutPage
    },
    {
        path: '/announcement-list',
        name: 'AnnouncementList',
        component: AnnouncementList
    },
    {
        path: '/platform-convention',
        name: 'PlatformConvention',
        component: () => import('../views/PlatformConvention.vue')
    },
    {
        path: '/announcement-list/:id',
        name: 'AnnouncementDetail',
        component: () => import('../views/AnnouncementDetail.vue')
    },
    {
        path: '/download-resources',
        name: 'DownloadResources',
        component: DownloadResources
    },
    // 404处理
    {
        path: '/:pathMatch(.*)*',
        name: 'NotFound',
        component: () => import('../views/ErrorPage.vue')
    }
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

// 全局错误处理
router.onError((error) => {
    console.error('路由错误:', error)
    router.push({ name: 'NotFound' })
})

export default router